package com.sskj.mine.ui.fragment;

import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bulong.rudeness.RudenessScreenHelper;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseFragment;
import com.sskj.lib.mvchelper.ModelRx2DataSource;
import com.sskj.lib.util.TimeFormatUtil;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.bean.OtherAssetBean;
import com.sskj.mine.presenter.OtherAssetPresenter;


import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @author Hey
 * Create at  2019/05/18
 */
@Route(path = RConfig.MINE_FRAGMENT_OTHER_ASSET)
public class OtherAssetFragment extends BaseFragment<OtherAssetPresenter> {


    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.coolRefreshView)
    CoolRefreshView coolRefreshView;


    @Override
    public int getLayoutId() {
        return R.layout.mine_fragment_other_asset;
    }

    @Override
    public OtherAssetPresenter getPresenter() {
        return new OtherAssetPresenter();
    }

    @Override
    public void initView() {
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(getActivity())
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 1))
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.mine_BEC))
        );
        SlimAdapter slimAdapter = SlimAdapter.create().register(R.layout.mine_recy_item_other_asset, new SlimInjector<OtherAssetBean>() {
            @Override
            public void onInject(OtherAssetBean data, IViewInjector injector, List payloads) {

                injector
                        .text(R.id.tv_title, data.getMemo())
                        .text(R.id.tvNum, data.getPrice()+" CQTF")
                        .text(R.id.date, data.getAddtime());
            }
        }).attachTo(recyclerView).updateData(new ArrayList());
        ModelRx2DataSource<OtherAssetBean> dataSource = new ModelRx2DataSource<>((ModelRx2DataSource.OnLoadSource<OtherAssetBean>)
                page -> mPresenter.getOtherAssetRecord(page + "", "20"), 20);
        MVCCoolHelper<List<OtherAssetBean>> mvcHelper = new MVCCoolHelper<>(coolRefreshView);
        mvcHelper.setDataSource(dataSource);
        mvcHelper.setAdapter(slimAdapter);
        mvcHelper.refresh();
    }
}
